package com.cade.agriculturemall.view.personalCenter.discount.storeDiscountFragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.cade.agriculturemall.R;
import com.cade.agriculturemall.base.BaseFragment;
import com.cade.agriculturemall.model.Ticket;
import com.cade.agriculturemall.widget.EmptyLayout;

import java.util.List;

/**
 * Created by hshunxin on 2018/2/24.
 */

public class StoreDiscountFragment extends BaseFragment<StoreDiscountContract.IPresenter> implements StoreDiscountContract.IView, StoreDiscountAdapter.MyClickListener {
    private RecyclerView mRecyclerView;
    private StoreDiscountAdapter mStoreDiscountAdapter;
    private EmptyLayout emptyLayout;

    @Override
    public int setupLayout() {
        return R.layout.activity_store_discount_fragment;
    }

    @Override
    public void setupView() {
        emptyLayout = (EmptyLayout) getView().findViewById(R.id.store_discount_emptylayout);
        mRecyclerView = (RecyclerView) getView().findViewById(R.id.store_discount_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

    @Override
    public void setupEvent() {

    }

    @Override
    public void setupData() {
        emptyLayout.loading();
        mPresenter.downTicket();
    }

    @Override
    public StoreDiscountContract.IPresenter setupPresenter() {
        return new StoreDiscountPresenter(this);
    }


    @Override
    public void getStoreTicket(List<Ticket> storeList) {
        emptyLayout.reset();
        if (storeList.size() == 0) {
            emptyLayout.empty();
        } else {
            mStoreDiscountAdapter = new StoreDiscountAdapter(this, storeList);
            mRecyclerView.setAdapter(mStoreDiscountAdapter);
        }
    }


    @Override
    public void clickListener(String ticketId) {
        Toast.makeText(getActivity(), "领取成功", Toast.LENGTH_SHORT).show();
        mPresenter.gainTicket(ticketId);
        mStoreDiscountAdapter.notifyDataSetChanged();
    }

    @Override
    public void emptyListener() {
        emptyLayout.empty();
    }

}
